﻿using Architecture.Api.Application.Commands.SlaughterCommand;
using Architecture.Domain.Services.Interface;
using Architecture.Domain.TraceabilityManage;
using MediatR;

namespace Architecture.Api.Application.CommandHandlers.SlaughterHandler
{
    public class SlaughterCreateCommandHandler : IRequestHandler<SlaughterCreateCommand, int>
    {

        private readonly ISlaughterService _slaughterservice;

        public SlaughterCreateCommandHandler(ISlaughterService slaughterservice)
        {
            _slaughterservice = slaughterservice;
        }

        public async Task<int> Handle(SlaughterCreateCommand request, CancellationToken cancellationToken)
        {
            return await _slaughterservice.AddSlaughter(new Slaughter
            {
                SId = request.SId,
                ProductionLot = request.ProductionLot,
                RelevantQualification = request.RelevantQualification,
                SlaughteringCompanyId = request.SlaughteringCompanyId,
                ArrivalTime = Convert.ToDateTime(request.ArrivalTime),
                SlaughterTime = Convert.ToDateTime(request.SlaughterTime),
                WeightToFactory = request.WeightToFactory,
            });
        }
    }
}
